package com.settlement.system.service.csv;

import com.settlement.system.model.entity.common.TblWpAuditCloseAccount;
import com.settlement.system.service.IBaseService;
import com.settlement.system.service.ITblWpAuditCloseAccountService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 唯品明细 多线程导出
 *
 * @author Ximi
 * @since 2020/12/16
 */
@Slf4j
public class WpAuditCsvDatas extends BaseServiceCsvDatas {

    private ITblWpAuditCloseAccountService accountService;

    public WpAuditCsvDatas(ITblWpAuditCloseAccountService accountService, IBaseService baseService, Map<String, Object> params) {
        super(baseService, params);
        this.accountService = accountService;
    }

    @Override
    protected List<Map<String, Object>> getListParams(Map<String, Object> params) {
        try {
            List<Map<String, Object>> list = new ArrayList<>();
            List<TblWpAuditCloseAccount> closeAccounts = accountService.selectByParam(params);
            for (TblWpAuditCloseAccount closeAccount : closeAccounts) {
                if(StringUtils.isBlank(closeAccount.getShopNo())){
                    continue;
                }
                HashMap<String, Object> map = (HashMap<String, Object>) ((HashMap<String, Object>) params).clone();
                map.put("shopNo", closeAccount.getShopNo());
                list.add(map);
            }
            return list;
        } catch (Exception ex) {
            log.error("唯品明细拆单条件异常", ex);
        }
        return super.getListParams(params);
    }
}
